<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form" %>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<style type="text/css">
	.error {
	  color: red;
	 }
</style>
</head>
<body>
 

<form:form modelAttribute="product" method="POST" action="">
<form:errors path="" cssClass="error"/>
<c:if test="${productExists}">
	<td><c:out value="Product with that name alreadry exits!"/></td>
</c:if>
<form:hidden path="productId" />
 <table>
  <tr>
   <td><form:label path="name">name:</form:label></td>
   <td><form:input path="name"/></td>
   <td><form:errors path="name" cssClass="error"/></td>
  </tr>
  
  <tr>
   <td><form:label path="description">description:</form:label></td>
   <td><form:input type="description" path="description"/></td>
   <td><form:errors path="description" cssClass="error"/></td>
  </tr>
  
  
  <tr>
   <td><form:label path="actualPrice">actualPrice:</form:label></td>
   <td><form:input path="actualPrice"/></td>
   <td><form:errors path="actualPrice" cssClass="error"/></td>
  </tr>
  
  <tr>
   <td><form:label path="stock">stock:</form:label></td>
   <td><form:input path="stock"/></td>
   <td><form:errors path="stock" cssClass="error"/></td>
  </tr>
	
	<tr>
   <td><form:label path="image">image:</form:label></td>
   <td><form:input path="image"/></td>
   <td><form:errors path="image" cssClass="error"/></td>
  </tr>
  
  <tr>
  <td><form:label path="category.name">category</form:label></td>
  <td><form:input type="list" path="category.name" list="categoriesList" name="categoryName" autocomplete="off"/></td>
 <datalist id="categoriesList">
	 <c:forEach var="cat" items="${categoryNames}" varStatus="status">
	 	<option value="${cat}">
	 </c:forEach>
</datalist>

<c:if test="${categoryNotExists}">
	<td><c:out value="Category with that name doesn't exist!"/></td>
</c:if>

<!--   <input list="browsers" name="browser"> -->

<%--    <td><form:label path="category.categoryId">categoryId</form:label></td> --%>
<%--    <td><form:input path="category.categoryId"/></td> --%>
<%--    <c:if test="${categoryNotExists}"> --%>
<%-- 		<td><c:out value="Category with that id doesn't exist!"/></td> --%>
<%-- 	</c:if> --%>
  </tr>

 </table>
 <table>
 <tr>
 <c:if test="${!add}">
 	<td><input type="submit"  name="action"  value="Save" /></td>
</c:if>
 <c:if test="${add}">
 	<td><input type="submit"  name="action"  value="Add" /></td>
</c:if>
<c:url var="backUrl" value="/admin/product" >
 		<c:param name="categoryId" value="${category.categoryId}" />
</c:url>
<td> <a href='<c:out value="${backUrl}"/>'>back</a> </td>
</tr>
</table>
</form:form>
</body>
</html>